package com.cskaoyan.controller.wxcontroller;


import com.cskaoyan.bean.bo.wx.WxExpressQueryBo;
import com.cskaoyan.bean.pojo.Order;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.wx.WxExpressQueryVo;
import com.cskaoyan.bean.vo.wx.groupondetail.WxTraceVo;
import com.cskaoyan.service.GoodsService;
import com.cskaoyan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author: lsy
 * @class: ExpressController
 * @description: 物流查询
 */
@RestController
@RequestMapping("/wx/express")
public class ExpressController {

    @Autowired
    GoodsService goodsService;
    OrderService orderService;

    @PostMapping("query")
    public BaseRespVo query(@RequestBody WxExpressQueryBo wxExpressQueryBo) {
        Order order = goodsService.queryOrderByOrderId(wxExpressQueryBo.getExpCode());

        WxExpressQueryVo wxExpressQueryVo = new WxExpressQueryVo();
        wxExpressQueryVo.setLogisticCode(order.getShipSn());
        wxExpressQueryVo.setShipperName(order.getShipChannel());

        WxTraceVo wxTraceVo = new WxTraceVo();
        if (order.getOrderStatus() == 401) {
            wxTraceVo.setAcceptStation("用户确认收货");
        } else if (order.getOrderStatus() == 402) {
            wxTraceVo.setAcceptStation("系统确认收货");
        } else {
            wxTraceVo.setAcceptStation("未收货");
        }
        wxTraceVo.setAcceptTime(order.getConfirmTime());
        wxTraceVo.setId(1);
        ArrayList<WxTraceVo> wxTraceVos = new ArrayList<>();
        wxTraceVos.add(wxTraceVo);
        wxExpressQueryVo.setTraces(wxTraceVos);
        return BaseRespVo.ok(wxExpressQueryVo);
    }
}
